//
//  RegisterViewController.m
//  mosad_hw_fin
//
//  Created by student9 on 2021/1/5.
//  Copyright © 2021 student9. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController () {
    NSString *ID;
    NSString *name;
    NSString *gender;
    NSString *psd;
    NSString *psd_ch;
}
@property (nonatomic, strong) UILabel *warningLabel;
@property (nonatomic, strong) UIButton *register_btn;
@property (nonatomic, strong) UIButton *boy_btn;
@property (nonatomic, strong) UIButton *girl_btn;
@property (nonatomic, strong) UILabel *genderLabel;
@property (nonatomic, strong) UILabel *textLabel;
@property (nonatomic, strong) JVFloatLabeledTextField *IDTF;
@property (nonatomic, strong) JVFloatLabeledTextField *usernameTF;
@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self nameLabel];
    
}

- (void)nameLabel {
    __weak typeof(self) weakSelf = self;
    
    UIButton *back_btn;
    back_btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    back_btn.frame = CGRectMake(0, 0, 40, 40);
    back_btn.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"leftarrow.png"] TransformtoSize:CGSizeMake(40, 40)]];
    [back_btn addTarget:self
                 action:@selector(back_to_mine:)
       forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:back_btn];
    [back_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).offset(30);
        make.left.equalTo(weakSelf.view).offset(20);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 30, 30)];
    _textLabel.text = @"请输入ID和用户名";
    _textLabel.font = [UIFont fontWithName:@"FZZJ-TJHWBJW"  size:(30)];
    _textLabel.textAlignment = NSTextAlignmentCenter;
    _textLabel.textColor = [UIColor colorWithRed:123/255.0 green:104/255.0 blue:238/255.0 alpha:1];
    [self.view addSubview:_textLabel];
    [_textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(back_btn.mas_top).offset(10);
        // 添加大小约束（make就是要添加约束的控件view）
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width - 30, 30));
        // 添加居中约束（居中方式与self相同）
        make.centerX.equalTo(self.view.mas_centerX);
    }];
    
    // 账号框
    // 输入框主体
    _IDTF = [[JVFloatLabeledTextField alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 100, 50)];
    // 边框线宽度
    _IDTF.layer.borderWidth = 1;
    // 边框线颜色
    _IDTF.layer.borderColor = [UIColor grayColor].CGColor;
    // 输入文字颜色
    _IDTF.textColor = [UIColor blackColor];
    // 浮动式标签的正常字体颜色
    _IDTF.floatingLabelTextColor = [UIColor grayColor];
    // 输入框成为第一响应者时,浮动标签的文字颜色.
    _IDTF.floatingLabelActiveTextColor = [UIColor blueColor];
    // 指明当输入文字时,是否下调基准线(baseline).设置为YES(非默认值),意味着占位内容会和输入内容对齐.
    _IDTF.keepBaseline = YES;
    // 允许编辑
    [_IDTF setEnabled:YES];
    // 设置初始占位符
    [_IDTF setPlaceholder:@"请输入邮箱或手机号"
                  floatingTitle:@"邮箱或手机号"];
    _IDTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    //关闭系统自动联想
    _IDTF.autocorrectionType=UITextAutocorrectionTypeNo;
    //关闭首字母大写
    _IDTF.autocapitalizationType=UITextAutocapitalizationTypeNone;
    // 设置边框类型
    [_IDTF setKeyboardType:UIKeyboardTypeDefault];
    [_IDTF setLeftView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 0)]];
    [_IDTF setLeftViewMode:UITextFieldViewModeAlways];
    UIColor *colorID = [UIColor whiteColor];
    _IDTF.backgroundColor = [colorID colorWithAlphaComponent:0.8];
    UIBezierPath * maskPathID = [UIBezierPath bezierPathWithRoundedRect:_IDTF.bounds cornerRadius:10];
    CAShapeLayer * maskLayerID = [[CAShapeLayer alloc] init];
    maskLayerID.frame = _IDTF.bounds;
    maskLayerID.path = maskPathID.CGPath;
    _IDTF.layer.mask = maskLayerID;
    [_IDTF addTarget:self
                    action:@selector(textFieldDidChangeID:)
          forControlEvents:UIControlEventEditingChanged];
    [self.view addSubview:_IDTF];
    [_IDTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_textLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(weakSelf.view.frame.size.width - 100, 50));
        make.centerX.equalTo(weakSelf.view.mas_centerX);
    }];
    
    // 账号框
    // 输入框主体
    _usernameTF = [[JVFloatLabeledTextField alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 100, 50)];
    // 边框线宽度
    _usernameTF.layer.borderWidth = 1;
    // 边框线颜色
    _usernameTF.layer.borderColor = [UIColor grayColor].CGColor;
    // 输入文字颜色
    _usernameTF.textColor = [UIColor blackColor];
    // 浮动式标签的正常字体颜色
    _usernameTF.floatingLabelTextColor = [UIColor grayColor];
    // 输入框成为第一响应者时,浮动标签的文字颜色.
    _usernameTF.floatingLabelActiveTextColor = [UIColor blueColor];
    // 指明当输入文字时,是否下调基准线(baseline).设置为YES(非默认值),意味着占位内容会和输入内容对齐.
    _usernameTF.keepBaseline = YES;
    // 允许编辑
    [_usernameTF setEnabled:YES];
    // 设置初始占位符
    [_usernameTF setPlaceholder:@"请输入用户名"
                 floatingTitle:@"用户名"];
    _usernameTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    //关闭系统自动联想
    _usernameTF.autocorrectionType=UITextAutocorrectionTypeNo;
    //关闭首字母大写
    _usernameTF.autocapitalizationType=UITextAutocapitalizationTypeNone;
    // 设置边框类型
    [_usernameTF setKeyboardType:UIKeyboardTypeDefault];
    // 设置一个左边的空白空间，防止文字直接贴边，并设置为总是显示UITextFieldViewModeAlways
    [_usernameTF setLeftView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 0)]];
    [_usernameTF setLeftViewMode:UITextFieldViewModeAlways];
    // 设置背景颜色，为了美观设置了透明度
    UIColor *color = [UIColor whiteColor];
    _usernameTF.backgroundColor = [color colorWithAlphaComponent:0.8];
    UIBezierPath * maskPathUsername = [UIBezierPath bezierPathWithRoundedRect:_usernameTF.bounds cornerRadius:10];
    CAShapeLayer * maskLayerUsername = [[CAShapeLayer alloc] init];
    maskLayerUsername.frame = _usernameTF.bounds;
    maskLayerUsername.path = maskPathUsername.CGPath;
    _usernameTF.layer.mask = maskLayerUsername;
    // 监听事件UIControlEventEditingChanged，当输入的内容改变之后，便调用textFieldDidChangeDate
    [_usernameTF addTarget:self
                   action:@selector(textFieldDidChangeUsername:)
         forControlEvents:UIControlEventEditingChanged];
    [self.view addSubview:_usernameTF];
    [_usernameTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_IDTF.mas_bottom).offset(10);
        // 添加大小约束（make就是要添加约束的控件view）
        make.size.mas_equalTo(CGSizeMake(weakSelf.view.frame.size.width - 100, 50));
        // 添加居中约束（居中方式与self相同）
        make.centerX.equalTo(weakSelf.view.mas_centerX);
    }];
    
    
    _genderLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 100, 50)];
    _genderLabel.text = @"选择你的性别";
    _genderLabel.font = [UIFont fontWithName:@"FZZJ-TJHWBJW"  size:(30)];
    _genderLabel.textAlignment = NSTextAlignmentCenter;
    _genderLabel.textColor = [UIColor colorWithRed:123/255.0 green:104/255.0 blue:238/255.0 alpha:1];
    [self.view addSubview:_genderLabel];
    [_genderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_usernameTF.mas_bottom).offset(10);
        // 添加大小约束（make就是要添加约束的控件view）
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width - 100, 50));
        // 添加居中约束（居中方式与self相同）
        make.centerX.equalTo(self.view.mas_centerX);
    }];
    
    
    _boy_btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _boy_btn.frame = CGRectMake(0, 0, 100, 100);
    _boy_btn.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"boy.jpg"] TransformtoSize:CGSizeMake(100, 100)]];
    [_boy_btn addTarget:self
                     action:@selector(boyPress:)
           forControlEvents:UIControlEventTouchUpInside];
    _boy_btn.layer.cornerRadius = 50;
    _boy_btn.layer.masksToBounds = YES;
    [self.view addSubview:_boy_btn];
    [_boy_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_genderLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(100, 100));
        make.left.equalTo(weakSelf.view).offset(60);
    }];
    
    _girl_btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _girl_btn.frame = CGRectMake(0, 0, 100, 100);
    _girl_btn.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"girl.jpg"] TransformtoSize:CGSizeMake(100, 100)]];
    [_girl_btn addTarget:self
                action:@selector(girlPress:)
      forControlEvents:UIControlEventTouchUpInside];
    _girl_btn.layer.cornerRadius = 50;
    _girl_btn.layer.masksToBounds = YES;
    [self.view addSubview:_girl_btn];
    [_girl_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_genderLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(100, 100));
        make.right.equalTo(weakSelf.view).offset(-60);
    }];
    
    UILabel *psdLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 100, 50)];
    psdLabel.text = @"请输入你的密码";
    psdLabel.font = [UIFont fontWithName:@"FZZJ-TJHWBJW"  size:(30)];
    psdLabel.textAlignment = NSTextAlignmentCenter;
    psdLabel.textColor = [UIColor colorWithRed:123/255.0 green:104/255.0 blue:238/255.0 alpha:1];
    [self.view addSubview:psdLabel];
    [psdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_girl_btn.mas_bottom).offset(10);
        // 添加大小约束（make就是要添加约束的控件view）
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width - 100, 50));
        // 添加居中约束（居中方式与self相同）
        make.centerX.equalTo(self.view.mas_centerX);
    }];
    
    // 密码框
    // 输入框主体
    JVFloatLabeledTextField *passwordTF = [[JVFloatLabeledTextField alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 100, 50)];
    // 边框线宽度
    passwordTF.layer.borderWidth = 1;
    // 边框线颜色
    passwordTF.layer.borderColor = [UIColor grayColor].CGColor;
    // 输入文字颜色
    passwordTF.textColor = [UIColor blackColor];
    // 浮动式标签的正常字体颜色
    passwordTF.floatingLabelTextColor = [UIColor grayColor];
    // 输入框成为第一响应者时,浮动标签的文字颜色.
    passwordTF.floatingLabelActiveTextColor = [UIColor blueColor];
    // 指明当输入文字时,是否下调基准线(baseline).设置为YES(非默认值),意味着占位内容会和输入内容对齐.
    passwordTF.keepBaseline = YES;
    // 密码隐藏
    passwordTF.secureTextEntry = YES;
    // 允许编辑
    [passwordTF setEnabled:YES];
    // 设置初始占位符
    [passwordTF setPlaceholder:@"请输入密码"
                 floatingTitle:@"密码"];
    passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    //关闭系统自动联想
    passwordTF.autocorrectionType=UITextAutocorrectionTypeNo;
    //关闭首字母大写
    passwordTF.autocapitalizationType=UITextAutocapitalizationTypeNone;
    // 设置边框类型
    [passwordTF setKeyboardType:UIKeyboardTypeDefault];
    // 设置一个左边的空白空间，防止文字直接贴边，并设置为总是显示UITextFieldViewModeAlways
    [passwordTF setLeftView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 0)]];
    [passwordTF setLeftViewMode:UITextFieldViewModeAlways];
    // 设置背景颜色，为了美观设置了透明度
    UIColor *colorPassword = [UIColor whiteColor];
    passwordTF.backgroundColor = [colorPassword colorWithAlphaComponent:0.8];
    UIBezierPath * maskPathPassword = [UIBezierPath bezierPathWithRoundedRect:passwordTF.bounds cornerRadius:10];
    CAShapeLayer * maskLayerPassword = [[CAShapeLayer alloc] init];
    maskLayerPassword.frame = passwordTF.bounds;
    maskLayerPassword.path = maskPathPassword.CGPath;
    passwordTF.layer.mask = maskLayerPassword;
    // 监听事件UIControlEventEditingChanged，当输入的内容改变之后，便调用textFieldDidChangeDate
    [passwordTF addTarget:self
                   action:@selector(textFieldDidChangePassword:)
         forControlEvents:UIControlEventEditingChanged];
    [self.view addSubview:passwordTF];
    [passwordTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(psdLabel.mas_bottom).offset(10);
        // 添加大小约束（make就是要添加约束的控件view）
        make.size.mas_equalTo(CGSizeMake(weakSelf.view.frame.size.width - 100, 50));
        // 添加居中约束（居中方式与self相同）
        make.centerX.equalTo(weakSelf.view.mas_centerX);
    }];
    
    // 密码确认框
    // 输入框主体
    JVFloatLabeledTextField *charifypasswordTF = [[JVFloatLabeledTextField alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 100, 50)];
    // 边框线宽度
    charifypasswordTF.layer.borderWidth = 1;
    // 边框线颜色
    charifypasswordTF.layer.borderColor = [UIColor grayColor].CGColor;
    // 输入文字颜色
    charifypasswordTF.textColor = [UIColor blackColor];
    // 浮动式标签的正常字体颜色
    charifypasswordTF.floatingLabelTextColor = [UIColor grayColor];
    // 输入框成为第一响应者时,浮动标签的文字颜色.
    charifypasswordTF.floatingLabelActiveTextColor = [UIColor blueColor];
    // 指明当输入文字时,是否下调基准线(baseline).设置为YES(非默认值),意味着占位内容会和输入内容对齐.
    charifypasswordTF.keepBaseline = YES;
    // 密码隐藏
    charifypasswordTF.secureTextEntry = YES;
    // 允许编辑
    [charifypasswordTF setEnabled:YES];
    // 设置初始占位符
    [charifypasswordTF setPlaceholder:@"请再次输入密码"
                        floatingTitle:@"密码确认"];
    charifypasswordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    //关闭系统自动联想
    charifypasswordTF.autocorrectionType=UITextAutocorrectionTypeNo;
    //关闭首字母大写
    charifypasswordTF.autocapitalizationType=UITextAutocapitalizationTypeNone;
    // 设置边框类型
    [charifypasswordTF setKeyboardType:UIKeyboardTypeDefault];
    // 设置一个左边的空白空间，防止文字直接贴边，并设置为总是显示UITextFieldViewModeAlways
    [charifypasswordTF setLeftView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 0)]];
    [charifypasswordTF setLeftViewMode:UITextFieldViewModeAlways];
    // 设置背景颜色，为了美观设置了透明度
    UIColor *colorPasswordCharity = [UIColor whiteColor];
    charifypasswordTF.backgroundColor = [colorPasswordCharity colorWithAlphaComponent:0.8];
    UIBezierPath * maskPathPasswordCharity = [UIBezierPath bezierPathWithRoundedRect:charifypasswordTF.bounds cornerRadius:10];
    CAShapeLayer * maskLayerPasswordCharity = [[CAShapeLayer alloc] init];
    maskLayerPasswordCharity.frame = charifypasswordTF.bounds;
    maskLayerPasswordCharity.path = maskPathPasswordCharity.CGPath;
    charifypasswordTF.layer.mask = maskLayerPasswordCharity;
    // 监听事件UIControlEventEditingChanged，当输入的内容改变之后，便调用textFieldDidChangeDate
    [charifypasswordTF addTarget:self
                          action:@selector(textFieldDidChangePasswordCharity:)
                forControlEvents:UIControlEventEditingChanged];
    [self.view addSubview:charifypasswordTF];
    [charifypasswordTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(passwordTF.mas_bottom).offset(10);
        // 添加大小约束（make就是要添加约束的控件view）
        make.size.mas_equalTo(CGSizeMake(weakSelf.view.frame.size.width - 100, 50));
        // 添加居中约束（居中方式与self相同）
        make.centerX.equalTo(weakSelf.view.mas_centerX);
    }];
    
    _warningLabel = [[UILabel alloc] init];
    _warningLabel.frame = CGRectMake(0, 0, self.view.frame.size.width - 100, 20);
    _warningLabel.textColor = [UIColor redColor];
    [self.view addSubview:_warningLabel];
    [_warningLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(charifypasswordTF.mas_bottom).offset(10);
        // 添加大小约束（make就是要添加约束的控件view）
        make.size.mas_equalTo(CGSizeMake(weakSelf.view.frame.size.width - 100, 20));
        // 添加居中约束（居中方式与self相同）
        make.centerX.equalTo(weakSelf.view.mas_centerX);
    }];
    
    // 注册按钮
    _register_btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _register_btn.frame = CGRectMake(0, 0, self.view.frame.size.width - 100, 50);
    _register_btn.backgroundColor = [UIColor colorWithRed:123/255.0 green:104/255.0 blue:238/255.0 alpha:0.8];
    [_register_btn setTitle:@"注册" forState:UIControlStateNormal];
    [_register_btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIBezierPath * maskPath_register = [UIBezierPath bezierPathWithRoundedRect:_register_btn.bounds cornerRadius:10];
    CAShapeLayer * maskLayer_register = [[CAShapeLayer alloc] init];
    maskLayer_register.frame = _register_btn.bounds;
    maskLayer_register.path = maskPath_register.CGPath;
    _register_btn.layer.mask = maskLayer_register;
    [_register_btn addTarget:self
                     action:@selector(pressName:)
           forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_register_btn];
    [_register_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_warningLabel.mas_bottom).offset(10);
        // 添加大小约束（make就是要添加约束的控件view）
        make.size.mas_equalTo(CGSizeMake(weakSelf.view.frame.size.width - 100, 50));
        // 添加居中约束（居中方式与self相同）
        make.centerX.equalTo(weakSelf.view.mas_centerX);
    }];
}



- (void) pressName:(UIButton *)buttonView {
    if ([self->gender isEqualToString:@"boy"] == NO && [self->gender isEqualToString:@"girl"] == NO) {
        self->_warningLabel.text = @"未选择性别";
        return ;
    }
    if ([self->ID isEqualToString:@""] == YES) {
        self->_warningLabel.text = @"邮箱或手机号不能为空";
        return ;
    }
    if ([self->name isEqualToString:@""] == YES) {
        self->_warningLabel.text = @"用户名不能为空";
        return ;
    }
    if ([self->psd isEqualToString:@""] == YES) {
        self->_warningLabel.text = @"密码不能为空";
        return ;
    }
    if ([self->psd_ch isEqualToString:self->psd] == NO) {
        self->_warningLabel.text = @"两次输入密码不一致";
        return ;
    }
    [self doPostRequestWithID:self->ID
                     WithName:self->name
                 WithPassword:self->psd];
}

- (void) doPostRequestWithID: (NSString *)ID
                    WithName:(NSString *)name
                WithPassword: (NSString *)pwd {
    AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    NSDictionary *dict = @{
                           @"ID":ID,
                           @"Name": name,
                           @"Password":pwd
                           };
    
    NSLog(@"dict: %@", dict);
    headimageModel *current_head_image = [headimageModel shareInstance];
    NSString *current_url = [current_head_image.host_str stringByAppendingString:@"User/Signup"];
    [manager POST:current_url
       parameters:dict
          headers:nil
         progress:^(NSProgress * _Nonnull downloadProgress) {
             //进度
         } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
             // 请求成功
             if ([responseObject[@"state"] boolValue]) {
                 dispatch_async(dispatch_get_main_queue(), ^{
                     self->_warningLabel.text = @"";
                     [self.navigationController popViewControllerAnimated:NO];
                 });
             } else {
                 dispatch_async(dispatch_get_main_queue(), ^{
                     self->_warningLabel.text = @"账号已存在";
                 });
             }
         } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
             // 请求失败
         }];
}


- (void) boyPress:(UIButton *)buttonView {
    self->gender = @"boy";
    self->_boy_btn.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"boy_select.png"] TransformtoSize:CGSizeMake(100, 100)]];
    self->_girl_btn.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"girl.jpg"] TransformtoSize:CGSizeMake(100, 100)]];
}

- (void) girlPress:(UIButton *)buttonView {
    self->gender = @"girl";
    self->_girl_btn.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"girl_select.png"] TransformtoSize:CGSizeMake(100, 100)]];
    self->_boy_btn.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"boy.jpg"] TransformtoSize:CGSizeMake(100, 100)]];
}

- (void) textFieldDidChangeID:(UITextField*) sender {
    self->ID = sender.text;
    if ([self->ID isEqualToString:@""] == YES) {
        _warningLabel.text = @"邮箱或手机号不能为空";
    } else {
        _warningLabel.text = @"";
        if([self->ID isEqualToString:@""] == NO) {
            [_register_btn setUserInteractionEnabled: YES];
        }
    }
}

- (void) textFieldDidChangeUsername:(UITextField*) sender {
    self->name = sender.text;
    if ([self->name isEqualToString:@""] == YES) {
        _warningLabel.text = @"用户名不能为空";
    } else {
        _warningLabel.text = @"";
        if([self->name isEqualToString:@""] == NO) {
            [_register_btn setUserInteractionEnabled: YES];
        }
    }
}

- (void) textFieldDidChangePassword:(UITextField*) sender {
    self->psd = sender.text;
    if ([self->psd isEqualToString:@""] == YES) {
        _warningLabel.text = @"密码不能为空";
    } else {
        _warningLabel.text = @"";
        if([self->psd isEqualToString:@""] == NO) {
            [_register_btn setUserInteractionEnabled: YES];
        }
    }
}

- (void) textFieldDidChangePasswordCharity:(UITextField*) sender {
    self->psd_ch = sender.text;
    if ([self->psd_ch isEqualToString:self->psd] == NO) {
        _warningLabel.text = @"两次输入密码不一致";
    } else {
        _warningLabel.text = @"";
        if( [self->psd_ch isEqualToString:self->psd] == YES) {
            [_register_btn setUserInteractionEnabled: YES];
        }
    }
}

- (void)back_to_mine:(UIButton *)buttonView {
    NSLog(@"back_to_mine");
    [self.navigationController popViewControllerAnimated:NO];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
